class Product:
    def __init__(self, name, price):
        self.name = name
        self.price = price

class Member:
    def __init__(self, level):
        self.level = level

    @property
    def discount_rate(self):
        # 根据会员等级返回折扣率
        if self.level == "普通会员":
            return 0.95  # 95折
        elif self.level == "银卡会员":
            return 0.90  # 9折
        elif self.level == "金卡会员":
            return 0.85  # 85折
        else:
            return 1.0   # 非会员无折扣

class CartItem:
    def __init__(self, product, qty, member=None):
        self.product = product
        self.qty = qty
        self.member = member

    def subtotal(self):
        return self.product.price * self.qty

    def discounted_subtotal(self):
        if self.member:
            return self.subtotal() * self.member.discount_rate
        else:
            return self.subtotal()

class ShoppingCart:
    def __init__(self):
        self.items = []

    def add(self, product, qty=1, member=None):
        self.items.append(CartItem(product, qty, member))

    def total(self):
        return sum(item.subtotal() for item in self.items)

    def discounted_total(self):
        return sum(item.discounted_subtotal() for item in self.items)

    def apply_discount(self):
        # 显示折扣信息
        if any(item.member for item in self.items):
            print("会员折扣已应用。")
        else:
            print("未应用会员折扣。")

    def show(self):
        print("-" * 30)
        for item in self.items:
            print(f"{item.product.name} ×{item.qty}\t￥{item.discounted_subtotal():.2f}")
        print("-" * 30)
        print(f"应付总额：￥{self.discounted_total():.2f}")
        self.apply_discount()

# --- 动态输入部分 ---
# 创建商品列表
products = [
    Product("苹果", 3.5),
    Product("面包", 4.0),
    Product("牛奶", 5.0),
    Product("鸡蛋", 2.0)
]

# 打印商品列表供用户选择
print("欢迎光临！请选择您要购买的商品：")
for idx, product in enumerate(products):
    print(f"{idx + 1}. {product.name} - ￥{product.price:.2f}")

# 创建购物车
cart = ShoppingCart()

# 输入会员等级
member_level = input("请输入您的会员等级（普通会员/银卡会员/金卡会员/非会员）：")
member = Member(member_level) if member_level != "非会员" else None

# 输入购买的商品
while True:
    try:
        choice = int(input("请输入商品编号（输入0结束购物）："))
        if choice == 0:
            break
        if 1 <= choice <= len(products):
            qty = int(input(f"您选择了 {products[choice - 1].name}，请输入购买数量："))
            cart.add(products[choice - 1], qty, member)
        else:
            print("无效的商品编号，请重新输入。")
    except ValueError:
        print("请输入有效的数字。")

# 显示购物清单和总价
cart.show()